package com.tqz.zookeeper.product;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 商品接口.
 *
 * @author <a href="https://github.com/tian-qingzhao">tianqingzhao</a>
 * @since 2025/9/7 15:53
 */

@RestController
@RequestMapping("product")
public class ProductController {

    private final Map<Integer, String> map = new HashMap<>();

    private Logger log = LoggerFactory.getLogger(ProductController.class);

    @Autowired
    private Environment env;

    @PostConstruct
    public void init() {
        map.put(1, "a");
        map.put(2, "b");
        map.put(3, "c");
    }

    @GetMapping("getById")
    public String getById(Integer id) {
        log.info("端口：{} 被调用了.", env.getProperty("server.port"));
        return map.getOrDefault(id, "商品不存在");
    }
}
